package com.leetcode.partition21;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/1/1 10:18
 */
public class LC2022将一维数组转变成二维数组 {

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] s = reader.readLine().split("\\s+");
        int[] nums = new int[s.length];
        for (int i = 0; i < s.length; i++) nums[i] = Integer.parseInt(s[i]);
        s = reader.readLine().split("\\s+");
        int n = Integer.parseInt(s[0]), m = Integer.parseInt(s[1]);
        int[][] ans = construct2DArray(nums, n, m);
        for (int i = 0; i < ans.length; i++) {
            for (int j = 0; j < ans[i].length; j++) {
                writer.write(ans[i][j] + " ");
            }
            writer.write("\n");
        }
        writer.flush();
    }

    public static int[][] construct2DArray(int[] original, int m, int n) {
        if (m * n != original.length) return new int[0][0];
        int[][] answer = new int[m][n];
        for (int i = 0; i < original.length; i++) {
            answer[i / n][i % n] = original[i];
        }
        return answer;
    }
}
